#include "mysql.h"
#include "logger.h"
#include <sstream>
static const std::string IP="127.0.0.1";
static unsigned short PORT=3306;
static const std::string& USER="root";
static const std::string& PASSWORD="1234";
static const std::string& DB="dsf";
void MySqlDB::ConnectMysqlServer(const std::string ip,unsigned short port,const std::string& user,
    const std::string& password,const std::string& db)
{
    if(!mysql_real_connect(m_mysqlClient,ip.c_str(),user.c_str(),password.c_str(),db.c_str(),3306,nullptr,0))
    {
        LOG_ERROR<<"mysql_real_connect() failed!";
    }
}
MySqlDB::~MySqlDB()
{
    if(m_mysqlClient!=nullptr)
    {
        mysql_close(m_mysqlClient);
    }
}
bool MySqlDB::query( std::string& sql)
{
    if(!mysql_query(m_mysqlClient,sql.c_str()))
    {
        LOG_ERROR<<"select failed!";
        return false;
    }
    return true;
}
int main()
{
    MySqlDB* m=MySqlDB::GetInstance();
    m->ConnectMysqlServer(IP,PORT,USER,PASSWORD,DB);

    std::string name="lsc";
    std::string password="1234";
    std::stringstream ss;
    ss<<"select * from user where name="<<name <<" and password="<<password;
    //snprintf(buf,LARGE_BUF_LEN,"select * from user where name = %s and password = %s",name.c_str(),password.c_str());

    m->query(ss.str());
}